package com.triones.api.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.FeeThaliDO;
import com.triones.api.entity.param.FeeThaliParams;
import com.triones.api.entity.vo.FeeThaliVO;
import com.triones.api.mapper.FeeThaliMapper;
import com.triones.api.service.FeeThaliService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 费用套餐 -业务实现
 */
@Service
@RequiredArgsConstructor
public class FeeThaliServiceImpl implements FeeThaliService {

    private final FeeThaliMapper feeThaliMapper;

    @Override
    public TableDataInfo<FeeThaliVO> pageList(FeeThaliParams feeThaliParams, PageQuery pageQuery) {
        LambdaQueryWrapper<FeeThaliDO> lqw = new LambdaQueryWrapper<FeeThaliDO>();
        lqw.like(FeeThaliDO::getStatus, "0");
        Page<FeeThaliVO> result = feeThaliMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    @Override
    public boolean addFeeThali(FeeThaliDO dto) {
        dto.setStatus("0");
        dto.setTakeEffectType("all");
        dto.setStartAt(System.currentTimeMillis());
        return feeThaliMapper.insert(dto) > 0;
    }

    @Override
    public FeeThaliVO getInfoByType(String type, String subType) {
        return feeThaliMapper.selectVoOne(new LambdaQueryWrapper<FeeThaliDO>()
            .eq(ObjectUtil.isNotEmpty(type),  FeeThaliDO::getType, type)
            .eq(ObjectUtil.isNotEmpty(subType),  FeeThaliDO::getSubType, subType)
            .last("limit 1"));
    }
}
